package Object;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @Auther: MFM
 * @Date: 2021/7/16 - 07 - 16 - 16:19
 * @version: 1.0
 */

public class OWork {
    public static void main(String[] args) {
        String str = "JKJjOJlkJKjlJhkhjvHJbjAKfCamkfnafkanKKnjankBBgsdfddasfdafaas";
        /*
            1.创建班长和小兵的一个序列
            2.区分出小兵和班长，班长按A-Z重新排列成一个新字符串 小兵不用排列
            3.小兵五个一割裂 给每一个班长
            4.若不够
              若多余
         */
        char[] banzhang = new char[0];
        char[] xiaobing = new char[0];

        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (ch >= 'A' && ch <= 'Z') {
                banzhang = Arrays.copyOf(banzhang, banzhang.length + 1);
                banzhang[banzhang.length - 1] = ch;
            } else {
                xiaobing = Arrays.copyOf(xiaobing, xiaobing.length + 1);
                xiaobing[xiaobing.length - 1] = ch;
            }
        }

        Arrays.sort(banzhang);

        int size = banzhang.length * 5 - xiaobing.length;

        if (size >= 0) {
            xiaobing = Arrays.copyOf(xiaobing, xiaobing.length + size);
            for (int i = xiaobing.length - size; i < xiaobing.length; i++) {
                xiaobing[i] = 'b';
            }
        }

        String NewString = "";

        int index = 0;
        for (int i = 0; i < banzhang.length; i++) {
            NewString = NewString.concat(String.valueOf(banzhang[i]));
            String bing = new String(xiaobing, index, 5);
            NewString = NewString.concat(bing);
            index+=5;
        }


        if (size >= 0) {
            System.out.println("小兵缺少" + size);
        } else {
            System.out.println("小兵多出" + size);
        }

        System.out.println(NewString);
    }
}
